<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="类别名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入类别名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="类别描述" prop="note">
        <el-input
          v-model="queryParams.note"
          placeholder="请输入类别描述"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="类别状态" prop="state">
        <el-input
          v-model="queryParams.state"
          placeholder="请输入类别状态"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="categoryList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="类别序号" align="center" prop="id" />
      <el-table-column label="类别名称" align="center" prop="name" />
      <el-table-column label="类别描述" align="center" prop="note" />
      <el-table-column label="类别状态" align="center" prop="state" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
          >删除</el-button> <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="detail(scope.row)"
          >详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改仓库信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="类别名称" prop="name">
          <el-input v-model="form.name" placeholder="请输入类别名称" />
        </el-form-item>
        <el-form-item label="类别描述" prop="note">
          <el-input v-model="form.note" placeholder="请输入类别描述" />
        </el-form-item>
        <el-form-item label="类别状态" prop="state">
          <el-input v-model="form.state" placeholder="请输入类别状态" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 添加或修改变更管理台账对象对话框 -->
    <el-dialog :title="detailtitle" :visible.sync="detailopen" width="800px" append-to-body>
      <el-form ref="detailform" :model="detailform" :rules="rules" label-width="80px">
        <el-form-item label="线路" prop="route">
          <el-input :disabled="true" v-model="detailform.route" placeholder="请输入线路" />
        </el-form-item>
        <el-form-item label="部门" prop="dept">
          <el-input :disabled="true" v-model="detailform.dept" placeholder="请输入部门" />
        </el-form-item>
        <el-form-item label="专业" prop="specialty">
          <el-input :disabled="true" v-model="detailform.specialty" placeholder="请输入专业" />
        </el-form-item>
        <el-form-item label="合同号" prop="contractId">
          <el-input :disabled="true"  v-model="detailform.contractId" placeholder="请输入合同号" />
        </el-form-item>
        <el-form-item label="承包单位" prop="contractUnit">
          <el-input :disabled="true" v-model="detailform.contractUnit" placeholder="请输入承包单位" />
        </el-form-item>
        <el-form-item label="台账编号" prop="accountNo">
          <el-input :disabled="true" v-model="detailform.accountNo" placeholder="请输入台账编号" />
        </el-form-item>
        <el-form-item label="变更内容">
          <editor v-model="detailform.changeContent" :min-height="192"/>
        </el-form-item>
        <el-form-item label="变更类型" prop="changeType">
          <el-select v-model="detailform.changeType" placeholder="请选择变更类型">
            <el-option
                v-for="dict in changeTypeOptions"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="变更时间" prop="changeDate">
          <el-date-picker clearable size="small"
                          v-model="detailform.changeDate"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="选择变更时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="变更会议纪要" prop="changeMeetingMinutes">
          <el-input v-model="detailform.changeMeetingMinutes" placeholder="请输入变更会议纪要" />
        </el-form-item>
        <el-form-item label="变更金额" prop="changeMoney">
          <el-input v-model="detailform.changeMoney" placeholder="请输入变更金额" />
        </el-form-item>
        <el-form-item label="变更流程完成情况" prop="completionProcess">
          <el-input v-model="detailform.completionProcess" placeholder="请输入变更流程完成情况" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="detailform.remark" placeholder="请输入备注" />
        </el-form-item>
      </el-form>
      <!--      <div slot="footer" class="dialog-footer">-->
      <!--        <el-button type="primary" @click="detailformcancel">确 定</el-button>-->
      <!--        <el-button @click="detailformcancel">取 消</el-button>-->
      <!--      </div>-->
    </el-dialog>
  </div>
</template>

<script>
import { listCategory, getCategory, delCategory, addCategory, updateCategory, exportCategory } from "@/api/emsboot/category";

export default {
  name: "Category",
  components: {
  },
  data() {
    return {
      detailform : {},
      detailopen : false,
      detailtitle: "",
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 仓库信息表格数据
      categoryList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        note: null,
        state: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询仓库信息列表 */
    getList() {
      this.loading = true;
      listCategory(this.queryParams).then(response => {
        this.categoryList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    /**详情按钮**/
    detail(row){
      this.reset();
      this.detailform = {
        route:"11",
        dept:"11",
        specialty:"11",
        contractId:"11",
        accountNo:"11",
        contractUnit:"11",
        changeContent:"11",

      };
      this.detailopen = true;
      this.detailtitle = "详情页变更管理台账对象";

    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        note: null,
        state: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getCategory(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateCategory(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addCategory(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除仓库信息编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delCategory(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    }
  }
};
</script>
